﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Model;
using FubiManger.Controls;

namespace FubiManger.UI
{
    partial class AddruleForm : Smobiler.Core.Controls.MobileForm
    {
        public AddruleForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        List<ms_packetrule> rulelist = new List<ms_packetrule>();
        /// <summary>
        /// 1添加2选择
        /// </summary>
        public string status { get; set; }
        /// <summary>
        /// 规则标题
        /// </summary>
        public string ruletitle { get; set; }
        /// <summary>
        /// 规则ID
        /// </summary>
        public string ruleid { get; set; }
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void AddruleForm_Load(object sender, EventArgs e)
        {
            merchantid = "2";
            rulelist = packetruleDal.Querybyid(merchantid);
            panrules.Height = rulelist.Count * 100;
            panall.Height = panrules.Height + 44;
            for (int i = 0; i < rulelist.Count; i++)
            {
                rulecontrol con = new rulecontrol();
                con.status = "0";
                con.ruletitle = rulelist[i].pk_ruletitle;//规则名称
                con.rule = rulelist[i].pk_rule;//规则
                con.status = status;
                con.ruleid = rulelist[i].pk_id;//规则ID
                panrules.Controls.Add(con);
            }
        }

        private void pandd_Press(object sender, EventArgs e)
        {
            panrules.Height +=1*100;
            panall.Height = panrules.Height + 44;
            rulecontrol con = new rulecontrol();
            con.status = "1";
            con.merchantid = merchantid;//商户ID
            con.index = panrules.Controls.Count;            
            panrules.Controls.Add(con);
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refsh()
        {
            if (panrules.Controls.Count > 0)
                panrules.Controls.Clear();
            rulelist = packetruleDal.Querybyid(merchantid);
            panrules.Height = rulelist.Count * 100;
            panall.Height = panrules.Height + 44;
            for (int i = 0; i < rulelist.Count; i++)
            {
                rulecontrol con = new rulecontrol();
                con.status = "0";
                con.ruletitle = rulelist[i].pk_ruletitle;
                con.rule = rulelist[i].pk_rule;
                con.status = status;
                con.ruleid = rulelist[i].pk_id;//规则编号
                panrules.Controls.Add(con);
            }
        }
        /// <summary>
        /// 设置规则
        /// </summary>
        /// <param name="tie"></param>
        /// <param name="rid"></param>
        public void Setrule(string tie,string rid)
        {
            ruleid = rid;//规则ID
            ruletitle = tie;//规则名称
            this.Close();
        }
    }
}